package org.shzhyun.pay.Service;

import com.alibaba.fastjson.JSONObject;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.shzhyun.pay.payment.JsApiPay;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@Slf4j
public class WechatPayManager {
//    @Autowired
//    private NativePay nativePay;

    @Autowired
    private JsApiPay jsApiPay;


//    public String createOrderNative(){
//        return nativePay.productOrder();
//    }

    public PrepayWithRequestPaymentResponse createOrderJsApi(JSONObject dto){
        return jsApiPay.productOrder(dto);
    }

//    public String callbackNative(HttpServletRequest request, HttpServletResponse response) {
//        String callback = "";
//        try {
//            callback = nativePay.callback(request, response);
//        }catch (Exception e){
//            log.error("callback exception :{}",e.getMessage());
//            e.printStackTrace();
//        }
//        return callback;
//    }

    public String callbackJsApi(HttpServletRequest request, HttpServletResponse response) {
        log.info("===>callbackJsApi=>request:{}",request);
        String callback = "";
        try {
            callback = jsApiPay.callback(request, response);
        }catch (Exception e){
            log.error("callback exception :{}",e.getMessage());
            e.printStackTrace();
        }
        return callback;
    }
}
